package com.benyq.networkprogramme

import android.app.Activity
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_add_friend.*


class AddFriendActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_add_friend)

        initView()
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        if (item?.itemId == android.R.id.home) {
            finish()
            return true
        }
        return super.onOptionsItemSelected(item)
    }

    private fun initView(){
        mainToolbar.title = "联系人"
        setSupportActionBar(mainToolbar)
        mainToolbar.navigationIcon = ContextCompat.getDrawable(this, R.drawable.ic_action_back)

        btnAdd.setOnClickListener {
            val ipAddress = etIpAddress.text.toString()
            val port: Int = etPort.text.toString().toInt()
            val name = etName.text.toString()
            val intent = Intent()
            with(intent){
                putExtra("ipAddress", ipAddress)
                putExtra("port", port)
                putExtra("name", name)
                setResult(Activity.RESULT_OK, this)
                finish()
            }
        }
    }


}
